﻿@{
    ViewBag.Title = "Architecture Summary";
}
@Scripts.Render("~/scripts/knockout.js")
@Scripts.Render("~/scripts/jquery-1.10.2.min.js")


<h2>Architecture Summary</h2>
<ul data-bind="foreach: architectureSummary, visible: architectureSummary().length > 0">
    <li>
        <p data-bind="text: Name" />
        @*<a href="#" data-bind="click: $parent.removeTask">Delete</a>*@
    </li>
</ul>


<script>
    function DesignPattern(data) {
        this.Name = ko.observable(data.Name);
    }

    function ArchitectureSummaryViewModel() {
        // Data
        var self = this;
        self.architectureSummary = ko.observableArray([]);
        self.newDesignPattern = ko.observable();
        //self.incompleteTasks = ko.computed(function () {
        //    return ko.utils.arrayFilter(self.tasks(), function (task) { return !task.isDone() });
        //});

        // Operations
        //self.addDesignPattern = function () {
        //    self.tasks.push(new Task({ Title: this.newTaskText() }));
        //    self.newTaskText("");
        //};

        //self.removeTask = function (task) { self.tasks.remove(task) };

        $.getJSON("/api/ArchitectureSummary", function (allData) {
            var mappedTasks = $.map(allData, function (item) { return new DesignPattern(item) });
            self.architectureSummary(mappedTasks);
        });


        //self.save = function () {
        //    $.ajax("/api/task", {
        //        data: ko.toJSON({ tasks: self.tasks()[0] }),
        //        type: "post", contentType: "application/json",
        //        success: function (result) { alert(result) }
        //    });
        //};


        //var booksUri = '/api/task/';

        //function ajaxHelper(uri, method, data) {
        //    //self.error(''); // Clear error message
        //    return $.ajax({
        //        type: method,
        //        url: uri,
        //        dataType: 'json',
        //        contentType: 'application/json',
        //        data: data ? JSON.stringify(data) : null
        //    }).fail(function (jqXHR, textStatus, errorThrown) {
        //        self.error(errorThrown);
        //    });
        //}

        //function getAllBooks() {
        //    ajaxHelper(booksUri, 'GET').done(function (data) {
        //        self.tasks(data);
        //    });
        //}

        //// Fetch the initial data.
        //getAllBooks();


    }
    ko.applyBindings(new ArchitectureSummaryViewModel());
</script>





